import Home from "../views/Home.vue"
import { createRouter, createWebHistory } from 'vue-router'
import store from '@/store/index.js'

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home
  },
  {
    path: "/itemMusic",
    name: "ItemMusic",
    component: () => import("../views/ItemMusic.vue")
  },
  {
    path: "/musicDetail",
    name: "musicDetail",
    component: () => import("../components/MusicDetail.vue")
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/infoUser',
    name: 'InfoUser',
    beforeEnter:(to,from,next)=>{
      if(store.state.isLogin || store.state.token || localStorage.getItem('token')){
        next()
      }else{
        next('/login')
      }
    },
    component: () => import('../views/InfoUser.vue')
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('../views/Search.vue')
  },
  {
    path: '/phone',
    name: 'phone',
    component: () => import('../views/Phone.vue')
  },
  {
    path: '/password',
    name: 'password',
    component: () => import('../views/password.vue')
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})


export default router